#include "vector_float.h"


vector_float::vector_float()
{
	vptr = nullptr;
	size = 0;
}

vector_float::vector_float(int s)
{
	create_vector(s);
}

vector_float::vector_float(const vector_float &original)
{
	create_vector(original.size);
	for (int i = 0; i < size; i++)
	{
		vptr[i] = original.vptr[i];
	}
}

vector_float::~vector_float()
{
	if (size != 0)
		delete_vector();
}

void vector_float::create_vector(int s)
{
	size = s;
	vptr = new float[this->size];
}

void vector_float::delete_vector()
{
	delete[] vptr;
	size = 0;
}

void vector_float::set(float value, int index)
{
	if (index >= 0 && index < size){
		vptr[index] = value;
	}
	else
	{
		cout << "error, invalid index" << endl;
	}
}


void vector_float::read_from_keyboard()
{
	cout << "ENTER VALUES FOR ALL ELEMENTS IN THE VECTOR" << endl;
	for (int i = 0; i < size; i++){
		cout << "Value " << i << ": ";
		cin >> vptr[i];
	}
	cout << "Done entering values..." << endl;
}

void vector_float::print()
{
	cout << "[";
	for (int i = 0; i < size; i++){
		cout << vptr[i];
		if (i == size - 1){
			cout << "]" << endl;
		}
		else
		{
			cout << ", ";
		}
	}
}

vector_float& vector_float::operator=(const vector_float &rop)
{
	if (size != 0)
		delete[] vptr;
	this->size = rop.size;
	this->vptr = new float[size];
	for (int i = 0; i < size; i++)
	{
		this->vptr[i] = rop.vptr[i];
	}
	return *this;
}